<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        v-model="form"
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
        :permission="permissionList">
        <template slot-scope="{row}" slot="menu">
          <el-switch v-model="row.guardStatus"
                     active-text="在岗"
                     inactive-text="未在岗"
                     active-value="1"
                     inactive-value="0"
                     @change="onStatusChange(row)">
          </el-switch>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import baseCrud from '@/mixins/base-crud'
import { setGuardStatus } from '@/api/support/swpmstationpersonguard'

export default {
  name: 'swpmstationpersonguard',
  mixins: [baseCrud('support/swpmstationpersonguard')],
  data() {
    return {}
  },
  computed: {
    permissionList() {
      return {
        addBtn: this.vaildData(this.permissions.support_sw_pm_station_person_guard_add, false),
        delBtn: this.vaildData(this.permissions.support_sw_pm_station_person_guard_del, false),
        editBtn: this.vaildData(this.permissions.support_sw_pm_station_person_guard_edit, false)
      };
    }
  },
  methods: {
    onStatusChange(row) {
      setGuardStatus(row.userCode, row.guardStatus).then(data => {}).catch(() => {
        this.$message.error('修改失败')
        this.getList(this.page)
      })
    }
  }
}
</script>
